/**
 * 
 */
package denaris.core;

import javax.microedition.lcdui.Graphics;

import denaris.core.controller.AbstractController;
import denaris.core.listener.IParticleListener;

/**
 * Represents one particle that was created by an emitter. Particles contain
 * information about their position and who they should inform about their
 * creation and destruction. There is NO setPosition method!! The particles
 * position must be changed via a Controller.
 * 
 * @author stkl23
 * 
 */
public abstract class AbstractParticle {
	/**
	 * an AbstractController can be used to control a particles movement path
	 * and its animation
	 */
	protected AbstractController controller;
	
	private IParticleListener particleListener;

	protected boolean active = false;

	public AbstractParticle(AbstractController controller) {
		setController(controller);
	}

	public AbstractController getController() {
		return controller;
	}

	public void setController(AbstractController controller) {
		this.controller = controller;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public void setPosition(int x, int y) {
		controller.getSprite().setPosition(x, y);
	}

	public abstract void paint(Graphics g);

	public abstract void update();

	public IParticleListener getParticleListener() {
		return particleListener;
	}

	public void setParticleListener(IParticleListener particleListener) {
		this.particleListener = particleListener;
	}
	
	protected void notifyOutOfScope() {
		if (particleListener  != null) {
			particleListener.particleOut(this);
		}
	}
}
